package com.example.controller;


import com.example.entity.Information;
import com.example.entity.KHZM;
import com.example.entity.Legalperson;
import com.example.entity.ZPerson;
import com.example.mapper.InformationMapper;
import com.example.service.IInformationService;
import com.example.service.impl.InformationServiceImpl;
import com.example.util.Code;
import com.example.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tyhxzy
 * @since 2023-11-03
 */
@RestController
@RequestMapping("/s/information")
public class InformationController {
    @Autowired
    private OccController controller;
    @Autowired
    private IInformationService informationService;
    //根据id查询全部信息
    @Autowired
    private InformationMapper informationMapper;
    @RequestMapping("/findByIdAll/{id}")
    public Result findByIdAll(@PathVariable Integer id){
        Information all = informationService.findAll(id);
        if (all!=null){
            return new Result(Code.GET_OK,all, "查询成功");
        }else {
            return new Result(Code.GET_ERR, "查询失败");
        }
    }


    @PostMapping("/add")
    public Result add(@RequestBody KHZM khzm){
        System.out.println(khzm);
        int add = informationService.add(khzm);
        return new Result(Code.SAVE_OK,khzm.getId(),"添加成功");
    }
    @GetMapping("/{zid}")
    public Result add(@PathVariable Integer zid){
        int i = informationMapper.addZid(zid);
        return new Result(Code.GET_OK,i,"成功");
    }
    @PostMapping("/addzidcard/{zid}")
    public Result addIdzCard(@RequestParam MultipartFile file, @PathVariable Integer zid) throws IOException {
        Result result = controller.uploadImg(file);
        Information information = new Information();
        information.setKhzm((String) result.getData());
        information.setZid(zid);
        int i = informationMapper.addzIdCard(information);
        return new Result(Code.GET_OK,i,"成功");
    }


}
